/**************************************************************************//**
 * @item     CosyOS-III Kernel
 * @file     ur_eapi.h
 * @brief    用户API扩展
 * @details  用户API的补充扩展定义，仅是定义无注释说明，所有内核服务的API说明
             均在 ur_api.h 中，并支持 doxygen。
 * @author   迟凯峰
 * @version  V1.2.0
 * @date     2025.03.30
 ******************************************************************************/

#ifndef __UR_EAPI_H
#define __UR_EAPI_H



/* 清除就绪延时 */
#define iClearDelay() sPSV_ClearDelay()
#define pClearDelay() sPS2_ClearDelay()

/* 恢复任务 */
#define tResumeTask(task)         sTSV_ResumeTask(u_taskhandle_##task)
#define iResumeTask(task)         sPSV_ResumeTask(u_taskhandle_##task)
#define pResumeTask(task)         sPS2_ResumeTask(u_taskhandle_##task)

/* 挂起任务 */
#define tSuspendTask(task)        sTSV_SuspendTask(u_taskhandle_##task)
#define iSuspendTask(task)        sPSV_SuspendTask(u_taskhandle_##task)
#define pSuspendTask(task)        sPS2_SuspendTask(u_taskhandle_##task)

/* 删除任务 */
#define tDeleteTask(task)         sTSV_DeleteTask(u_taskhandle_##task)
#define iDeleteTask(task)         sPSV_DeleteTask(u_taskhandle_##task)
#define pDeleteTask(task)         sPS2_DeleteTask(u_taskhandle_##task)

/* 设置任务优先级 */
#define tSetTaskPri(task, npri)   sTSV_SetTaskPri(u_taskhandle_##task, npri)
#define iSetTaskPri(task, npri)   sPSV_SetTaskPri(u_taskhandle_##task, npri)
#define pSetTaskPri(task, npri)   sPS2_SetTaskPri(u_taskhandle_##task, npri)

/* 清除阻塞（状态）*/
#define tClearBlock(task)         sTSV_ClearBlock(u_taskhandle_##task)
#define iClearBlock(task)         sPSV_ClearBlock(u_taskhandle_##task)
#define pClearBlock(task)         sPS2_ClearBlock(u_taskhandle_##task)

/* 设置阻塞-滴答周期 */
#define tSetBlock_tc(task, tc)    sTSV_SetBlock(u_taskhandle_##task, tc)
#define iSetBlock_tc(task, tc)    sPSV_SetBlock(u_taskhandle_##task, tc)
#define pSetBlock_tc(task, tc)    sPS2_SetBlock(u_taskhandle_##task, tc)

/* 设置阻塞-毫秒 */
#define tSetBlock_ms(task, ms)    tSetBlock_tc(task, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)
#define iSetBlock_ms(task, ms)    iSetBlock_tc(task, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)
#define pSetBlock_ms(task, ms)    pSetBlock_tc(task, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)

/* 设置阻塞-秒钟 */
#define tSetBlock_s(task, s)      tSetBlock_ms(task, 1000UL * (s))
#define iSetBlock_s(task, s)      iSetBlock_ms(task, 1000UL * (s))
#define pSetBlock_s(task, s)      pSetBlock_ms(task, 1000UL * (s))

/* 设置阻塞-分钟 */
#define tSetBlock_m(task, m)      tSetBlock_s(task, 60UL * (m))
#define iSetBlock_m(task, m)      iSetBlock_s(task, 60UL * (m))
#define pSetBlock_m(task, m)      pSetBlock_s(task, 60UL * (m))

/* 设置阻塞-小时 */
#define tSetBlock_h(task, h)      tSetBlock_m(task, 60UL * (h))
#define iSetBlock_h(task, h)      iSetBlock_m(task, 60UL * (h))
#define pSetBlock_h(task, h)      pSetBlock_m(task, 60UL * (h))

/* 定时中断-滴答周期 */
#define tTimInt_tc(tmid, tc)      sTSV_TimInt(tmid, tc)
#define iTimInt_tc(tmid, tc)      sPSV_TimInt(tmid, tc)

/* 定时中断-毫秒 */
#define tTimInt_ms(tmid, ms)      tTimInt_tc(tmid, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)
#define iTimInt_ms(tmid, ms)      iTimInt_tc(tmid, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)

/* 定时中断-秒钟 */
#define tTimInt_s(tmid, s)        tTimInt_ms(tmid, 1000UL * (s))
#define iTimInt_s(tmid, s)        iTimInt_ms(tmid, 1000UL * (s))

/* 定时中断-分钟 */
#define tTimInt_m(tmid, m)        tTimInt_s(tmid, 60UL * (m))
#define iTimInt_m(tmid, m)        iTimInt_s(tmid, 60UL * (m))

/* 定时中断-小时 */
#define tTimInt_h(tmid, h)        tTimInt_m(tmid, 60UL * (h))
#define iTimInt_h(tmid, h)        iTimInt_m(tmid, 60UL * (h))

/* 终止定时中断 */
#define tTimInt_Cancel(tmid)      tTimInt_tc(tmid, 0)
#define iTimInt_Cancel(tmid)      iTimInt_tc(tmid, 0)

/* 定时查询-滴答周期 */
#define tTimQry_tc(tmid, tc)      sTSV_TimQry(tmid, tc)
#define iTimQry_tc(tmid, tc)      sPSV_TimQry(tmid, tc)

/* 定时查询-毫秒 */
#define tTimQry_ms(tmid, ms)      tTimQry_tc(tmid, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)
#define iTimQry_ms(tmid, ms)      iTimQry_tc(tmid, (1000UL * (ms)) / SYSCFG_SYSTICK_CYCLE)

/* 定时查询-秒钟 */
#define tTimQry_s(tmid, s)        tTimQry_ms(tmid, 1000UL * (s))
#define iTimQry_s(tmid, s)        iTimQry_ms(tmid, 1000UL * (s))

/* 定时查询-分钟 */
#define tTimQry_m(tmid, m)        tTimQry_s(tmid, 60UL * (m))
#define iTimQry_m(tmid, m)        iTimQry_s(tmid, 60UL * (m))

/* 定时查询-小时 */
#define tTimQry_h(tmid, h)        tTimQry_m(tmid, 60UL * (h))
#define iTimQry_h(tmid, h)        iTimQry_m(tmid, 60UL * (h))

/* 终止定时查询 */
#define tTimQry_Cancel(tmid)      tTimQry_tc(tmid, ~0)
#define iTimQry_Cancel(tmid)      iTimQry_tc(tmid, ~0)

/* 上锁二值信号量 */
#define tLockBin(bin)             bin.binary = false
#define iLockBin(bin)             sPSV_WriteBin(bin, false)
#define pLockBin(bin)             sPS2_WriteBin(bin, false)

/* 给予二值信号量 */
#define tGiveBin(bin)             sTSV_GiveBin(bin)
#define iGiveBin(bin)             sPSV_WriteBin(bin, true)
#define pGiveBin(bin)             sPS2_WriteBin(bin, true)

/* 获取二值信号量 */
#define tTakeBin(bin)             sTSV_TakeBin(bin)
#define iTakeBin(bin)             sISV_TakeBin(bin)

/* 归还二值信号量 */
#define tBackBin(bin)             bin.binary = true
#define iBackBin(bin)             bin.binary = true

/* 给予计数信号量 */
#define tGiveSem(sem)             sTSV_GiveSem(sem)
#define iGiveSem(sem)             sPSV_GiveSem(sem)

/* 获取计数信号量 */
#define tTakeSem(sem)             sTSV_TakeSem(sem)

/* 归还计数信号量 */
#define tBackSem(sem)             tGiveSem(sem)

/* 接收飞信 */
#define tRecvFetion(tbox)         sTSV_RecvFetion(tbox)
#define iRecvFetion(tbox)         sISV_RecvFetion(tbox)

/* 发送飞信 */
#define tSendFetion(tbox, tion)   sTSV_SendFetion(tbox, tion)
#define iSendFetion(tbox, tion)   sPSV_SendFetion(tbox, tion)

/* 接收邮件 */
#define tRecvMail(mbox)           sTSV_RecvMail(mbox)
#define iRecvMail(mbox)           sISV_RecvMail(mbox)

/* 发送邮件 */
#define tSendMail(mbox, mail)     sTSV_SendMail(mbox, mail)
#define iSendMail(mbox, mail)     sPSV_SendMail(mbox, mail)

/* 接收消息 */
#define tRecvMsg(que)             sTSV_RecvMsg(que)
#define iRecvMsg(que)             sISV_RecvMsg(que)

/* 发送消息 */
#define tSendMsg(que, msg)        sTSV_SendMsg(que, msg)
#define iSendMsg(que, msg)        sPSV_SendMsg(que, msg)

/* 查询标志组 */
#define tQueryFlagGroup(group)    sTSV_QueryFlagGroup(group)
#define iQueryFlagGroup(group)    sISV_QueryFlagGroup(group)

/* 清除标志组 */
#define tClearFlagGroup(group)    sTSV_ClearFlagGroup(group)
#define iClearFlagGroup(group)    sPSV_ClearFlagGroup(group)

/* 设置标志位 */
#define tSetFlagBit(group, bit)   tSetFlagBits(group, 1) bit)
#define iSetFlagBit(group, bit)   iSetFlagBits(group, 1) bit)

/* 清除标志位 */
#define tClearFlagBit(group, bit) tClearFlagBits(group, 1) bit)
#define iClearFlagBit(group, bit) iClearFlagBits(group, 1) bit)

/* 设置多标志位 */
#define tSetFlagBits(group, nbit)   sTSV_WriteFlagBits(group, true, nbit)
#define iSetFlagBits(group, nbit)   sPSV_WriteFlagBits(group, +, nbit)

/* 清除多标志位 */
#define tClearFlagBits(group, nbit) sTSV_WriteFlagBits(group, false, nbit)
#define iClearFlagBits(group, nbit) sPSV_WriteFlagBits(group, -, nbit)

/* 获取时间 */
#define tGetTime(t)  sTSV_GetTime(t)
#define iGetTime(t)  sISV_GetTime(t)

/* 设置时间 */
#define tSetTime(t)  sTSV_SetTime(t)
#define iSetTime(t)  sPSV_SetTime(t)

/* 别名定义（API简化）*/
#define uRecvFet uRecvFetion
#define tRecvFet tRecvFetion
#define iRecvFet iRecvFetion
#define uSendFet uSendFetion
#define tSendFet tSendFetion
#define iSendFet iSendFetion



#endif
